/**
 * 专门处理 filters 的 reducer 函数
 */

const initialState = {
  status: "All",
  colors: [],
};

function filtersReducer(prevState = initialState, action) {
  switch (action.type) {
    case "STATUS_CHANGE":
      return {
        ...prevState,
        status: action.status,
      };

    case "COLORS_CHANGE":
      return {
        ...prevState,
        colors: prevState.colors.includes(action.color)
          ? prevState.colors.filter((item) => item !== action.color)
          : [...prevState.colors, action.color],
      };

    default:
      return prevState;
  }
}

export default filtersReducer;
